package demo.iterator;


import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.Iterator;

/**
 * @author : feixiang.li
 * @since : 2025-09-17 13:49
 */
@AllArgsConstructor
@NoArgsConstructor
@Data
public class User implements Iterable<String> {

    private String name;

    private Integer age;

    @Override
    public Iterator<String> iterator() {
        return new UserItr();
    }


    public class UserItr implements Iterator<String> {

        private int index = 0;

        @Override
        public boolean hasNext() {
            return index < 2;
        }

        @Override
        public String next() {
            index++;
            return index == 1 ? name : String.valueOf(age);
        }
    }
}
